<template>
  <div>
    <!--面包屑-->
    <bread :bread="$route.meta.bread" />
    <!--页面-->
    <el-card>
      <!--警告区-->
      <el-alert
        title="注意：只允许为第三级分类设置相关参数！"
        show-icon
        :closable="false"
        type="warning"
      >
      </el-alert>
      <!--选择商品分类-->
      <el-row>
        <el-col>
          <span>选择商品分类：</span>
          <!--级联选择框-->
          <el-cascader
            v-model="sck"
            :options="lclist"
            :props="cateprops"
            expandTrigger="hover"
            @change="handleChange"
          ></el-cascader>
        </el-col>
      </el-row>
      <!--页面-->
      <el-tabs v-model="activeName" @tab-click="handleTapClick">
        <!--动态参数-->
        <el-tab-pane label="动态参数" name="many">
          <el-button type="primary" size="mini" :disabled="isbtn">添加参数</el-button>
        </el-tab-pane>
        <!--静态属性-->
        <el-tab-pane label="静态属性" name="only">
          <el-button type="primary" size="mini" :disabled="isbtn">添加属性</el-button>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import bread from "./../bread";
export default {
  components: { bread },
  name: "",
  data() {
    return {
      lclist: [], //商品分类
      cateprops: {
        value: "cat_id",
        label: "cat_name",
        children: "children",
      }, //级联选择框
      sck: [], //级联双向绑定

      //页面
      activeName: "many",
    };
  },
  mounted() {
    this.getlist();
  },
  methods: {
    //商品分类列表
    async getlist() {
      let { data: res } = await this.$axios.get("categories");
      this.lclist = res;
      // console.log(this.lclist);
    },

    //级联选择框变化会触发
    async handleChange() {
      //不是三级分类
      console.log(this.sck);
      if (this.sck.length !== 3) {
        this.sck = [];
        return;
      }
      //是三级分类
      console.log(this.sck);
      //根据所选分类的id 获取 动态 或者 静态 数据
      let { data: res } = await this.$axios.get(`categories/${this.cateid}/attributes`, {
        params: { sel: this.activeName },
      });
      if (res.meta.status !== 200) {
        return this.$message.error(`获取参数列表失败`);
      }
      console.log(res.data);
    },
    //页面点击触发
    handleTapClick() {
      console.log(this.activeName);
    },
    //参数数据获取
  },
  computed: {
    //按钮禁用true  ，否则flase
    isbtn() {
      if (this.sck.length !== 3) {
        return true;
      }
      return false;
    },
    //选中的三级id
    cateid() {
      if (this.sck.length === 3) {
        return this.sck[2];
      }
      return null;
    },
  },
  watch: {},
};
</script>

<style lang="scss" scoped>
.el-row {
  margin: 15px 0px;
}
</style>
